﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynamicChart.Data;

namespace Sinochem.TMS.PurchaseChartService
{
    public class SupplierBuilder : IChartBuilder
    {
        public ChartPackage Build(DateRange dateRange, string parameterString)
        {
            ChartPackage package = new ChartPackage();

            package.Caption = "供应商采购额月信息分析";
            package.CellWidth = 0;
            package.CellHeight = 300;

            package.DateRange = new DateRange();
            package.DateRange.Mode = "m";
            package.DateRange.NextMode = string.Empty;
            package.DateRange.BeginDate = DateTime.Now.AddYears(-5);
            package.DateRange.CurrentDate = DateTime.Now;
            package.DateRange.EndDate = DateTime.Now.AddYears(5);
            package.DateRange.IsVisible = false;

            for (int index = 0; index < 12; index++)
            {
                ChartDefinition chartDef = new ChartDefinition
                {
                    Row = index / 3,
                    Col = index % 3,
                    RowSpan = 1,
                    ColSpan = 1,
                    Module = "purchase-supplier",
                    ParameterString = parameterString,
                };

                chartDef.DateRange = new DateRange();
                chartDef.DateRange.Mode = package.DateRange.Mode;
                chartDef.DateRange.NextMode = package.DateRange.NextMode;
                chartDef.DateRange.BeginDate = package.DateRange.BeginDate;
                chartDef.DateRange.CurrentDate = new DateTime(package.DateRange.CurrentDate.Year, index + 1, package.DateRange.CurrentDate.Day);
                chartDef.DateRange.EndDate = package.DateRange.EndDate;
                chartDef.DateRange.IsVisible = package.DateRange.IsVisible;

                package.ChartDefinitions.Add(chartDef);
            }

            return package;
        }
    }
}
